<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>

	<body>
	</body>
	<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
	<script type="text/javascript">
		var urlStr = "https://www.baidu.com/s?wd=css+%E4%B8%89%E8%A7%92&tn=78040160_59_pg&ie=utf8";
		var convertStr = encodeURIComponent(urlStr); //转换的原链接可能存在"&"这样的特殊符号，导致原链接的某些字段会被当做ajax请求的参数，所以最好先进行转码  
		console.log(getShortUrl(convertStr));

		function getShortUrl(urlStr) {
			$.ajax({
				type: 'GET',
				url: 'http://api.t.sina.com.cn/short_url/shorten.json?source=1681459862&url_long=' + urlStr, //source为新浪appkey，最好用自己的  
				dataType: 'JSONP',
				json: 'callback',
				data: {},
				success: function(r) {
					return r[0].url_short; //生成的短链接  
				}
			});
		}
	</script>

</html>